<template>
	<view>
		<view class="top-back">
			<view class="top-name">其他设置</view>
		</view>
		<view class="uni-container">
			<view class="query-back">
				<view>
					<uni-forms ref="baseForm">
						<uni-forms-item label="单个客户最大可关联用户数：" labelWidth="200" labelAlign="right">
							<view class="item-back">
								<uni-easyinput :clearable="false" v-model="numItme.value" placeholder="请输入" />
								<view class="item-right">个</view>
							</view>
						</uni-forms-item>
						<uni-forms-item label="已完结/已结案后：" labelWidth="200" labelAlign="right">
							<view class="item-back">
								<uni-easyinput :clearable="false" v-model="hourItem.value" placeholder="请输入" />
								<view class="item-right">小时归档</view>
							</view>
						</uni-forms-item>
					</uni-forms>
				</view>
				<view class="bottom-btn" @click="submitData">保存</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {

		data() {
			return {
				numCode: 'customer_max_relation_user_count',
				hourCode: 'case_archive_hours',

				numItme: {
					value: ''
				},
				hourItem: {
					value: ''
				}
			}
		},
		mounted() {
			this.requestData()
		},
		methods: {
			//网络请求示例
			async requestData() {
				let _this = this
				let parmas = {
					type: '0'
				};
				var url = "/comm/config/list";
				const res = await this.$myRequest({
					url: url,
					method: 'POST',
					data: parmas,
				})
				console.log('返回结果', res)
				if (res.data.code == 200) {
					for (var i = 0; i < res.data.data.list.length; i++) {
						var item = res.data.data.list[i];
						if (item.code == _this.numCode) {
							_this.numItme = item;
						}
						if (item.code == _this.hourCode) {
							_this.hourItem = item;
						}
					}
				}
			},
			//保存
			async submitData() {
				var jsInt = /^[0-9]+.?[0-9]*$/; //判断字符串是否为数字
				var jsPosInt = /^[1-9]+[0-9]*]*$/; //判断正整数
				if (!this.numItme.value) {
					uni.showToast({
						title: '请填写单个客户最大可关联用户数',
						icon: 'none'
					})
					return;
				}
				if (!this.hourItem.value) {
					uni.showToast({
						title: '请填写已完结/已结案后多少小时可以归档',
						icon: 'none'
					})
					return;
				}
				if (!jsPosInt.test(this.numItme.value) || !jsPosInt.test(this.hourItem.value)) {
					uni.showToast({
						title: '必须为正整数',
						icon: 'none'
					})
					return;
				}

				let _this = this
				var parms = {
					'id': this.numItme.id,
					'name': this.numItme.name,
					'value': this.numItme.value,
				}
				const res = await this.$myRequest({
					url: "/comm/config",
					method:'PUT',
					data: parms
				})
				if (res.data.code == 200) {
					var parms1 = {
						'id': _this.hourItem.id,
						'name': _this.hourItem.name,
						'value':_this.hourItem.value,
					}
					const res1 = await this.$myRequest({
						url: "/comm/config",
						method:'PUT',
						data: parms1
					})
					if (res1.data.code == 200) {
						uni.showToast({
							title: '保存成功'
						})
					}
				}
			},
		}
	}
</script>

<style scoped>
	.top-back {
		display: flex;
		align-items: center;
		padding: 10px;
	}

	.top-name {
		color: #333;
		font-size: 18px;
		font-weight: bold;
		margin-left: 30px;
	}



	.uni-container {
		margin-left: 40px;
		margin-right: 16px;
		width: auto;
	}

	.search-back {
		width: 100%;
		height: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
	}

	.search-noresult {
		font-size: 14px;
		color: #333;
		font-weight: 400;
	}

	.search-image {
		width: 150px;
		height: 150px;
	}

	.query-back {
		margin-top: 15px;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.bottom-btn {
		cursor: pointer;
		width: 104px;
		height: 32px;
		background: #2DA9C5;
		border-radius: 2px;
		color: #FFFFFF;
		font-size: 14px;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.item-back {
		display: flex;
		align-items: center;
	}

	.item-right {
		margin-left: 10px;
		color: #666;
		font-size: 14px
	}
</style>
